package handle

import (
	"fmt"

	"github.com/emicklei/go-restful/v3"
)

type Req struct {
}

func (r Req) InitRoute(container *restful.Container) {
	ws := new(restful.WebService)
	ws.Route(ws.POST("/req/form-data").To(r.form()))
	ws.Route(ws.POST("/req/form-ulencoded").To(r.formUrlencoded()))
	ws.Route(ws.GET("/req/path/{name}/:ext").To(r.path()))
	ws.Route(ws.GET("/req/query").To(r.query()))
	ws.Route(ws.POST("/req/binary").To(r.binary()))
	ws.Route(ws.POST("/req/raw").To(r.raw()))
	container.Add(ws)
}
func (r Req) form() restful.RouteFunction {
	return func(request *restful.Request, response *restful.Response) {
	}
}
func (r Req) formUrlencoded() restful.RouteFunction {
	return func(request *restful.Request, response *restful.Response) {
		fmt.Println(request.QueryParameters("name"))
		//fmt.Println(ctx.PostForm("name"))
	}
}
func (r Req) query() restful.RouteFunction {
	return func(request *restful.Request, response *restful.Response) {
		fmt.Println(request.QueryParameters("name"))
	}
}
func (r Req) path() restful.RouteFunction {
	return func(request *restful.Request, response *restful.Response) {
		fmt.Println(request.PathParameters())
	}
}
func (r Req) binary() restful.RouteFunction {
	return func(request *restful.Request, response *restful.Response) {
	}
}
func (r Req) raw() restful.RouteFunction {
	return func(request *restful.Request, response *restful.Response) {
		fmt.Println(request.BodyParameter("name"))
	}
}
